from rest_framework.views import APIView
from util.ip_address.ip_info import CzIp


class LX(APIView):
    def get(self, request):
        # 登陆成功后获取ip
        if request.META.get('HTTP_X_FORWARDED_FOR'):
            ip = request.META.get('HTTP_X_FORWARDED_FOR')
        else:
            ip = request.META.get('REMOTE_ADDR')
        print('======================', ip)

        # 设备的信息
        print(type(request))  # <class 'django.core.handlers.wsgi.WSGIRequest'>
        system = request.environ.get("HTTP_USER_AGENT")
        print('设备信息：', system)  # 全部返回的是个字典

        # 获取登陆地址
        cz = CzIp()
        places = cz.get_addr_by_ip(ip)
        print(places)


